package _base0to1;

/**
 * 66. 加一
 */
public class No66 {
    public int[] plusOne(int[] digits) {
        for (int right = digits.length - 1; right >= 0; right--) {
            if (digits[right] != 9) {
                digits[right] = digits[right] + 1;
                break;
            } else {
                digits[right] = 0;
                if (right == 0) {
                    int[] ints = new int[digits.length + 1];
                    System.arraycopy(digits, 0, ints, 1, digits.length);
                    ints[0] = 1;
                    digits = ints;
                }
            }
        }
        return digits;
    }
}
